package com.butuh.uang.tuh.ang.present;

import com.butuh.uang.tuh.ang.model.HomeListResult;
import com.butuh.uang.tuh.ang.net.Api;
import com.butuh.uang.tuh.ang.ui.DownHistoryActivity;
import com.butuh.uang.tuh.ang.util.JsonUtils;

import java.util.HashMap;

import cn.droidlover.xdroidmvp.log.XLog;
import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;
import okhttp3.RequestBody;

public class PDownloadHistory extends XPresent<DownHistoryActivity> {

    public void getHistoryList() {
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("920", "2");
        RequestBody body = JsonUtils.mapToBody(paramsMap);
        Api.getNetService().getList(JsonUtils.getAllParmarts(getV()), body)
                .compose(XApi.<HomeListResult>getApiTransformer())
                .compose(XApi.<HomeListResult>getScheduler())
                .compose(getV().<HomeListResult>bindToLifecycle())
                .subscribe(new ApiSubscriber<HomeListResult>() {
                    @Override
                    public void onNext(HomeListResult stBean) {
                        XLog.e("--token--" + stBean.toString());
                        getV().loadList(stBean.getBody().getDatum());
                    }

                    @Override
                    protected void onFail(NetError error) {
                        XLog.e("========" + error.getType() + "=====" + error.getMessage());
                        getV().loadListError(error.getType(), error.getMessage());
                    }
                });
    }




}
